package com.example.im;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.common.adapter.ViewPagerAdapter;
import com.example.common.base.AbsActivity;
import com.example.common.utils.L;
import com.example.common.utils.SPUtils;
import com.example.im.databinding.ActImMainBinding;
import com.example.im.fragment.ImConversationFragment;
import com.example.im.fragment.ImFriendsFragment;
import com.example.im.fragment.ImMyFragment;
import com.example.im.utils.MessageUtils;

import java.util.ArrayList;
import java.util.List;

import static com.example.common.utils.SPUtils.IM_LOGIN;
import static com.example.common.utils.SPUtils.XIAOMI_PUSH_REGID;

@Route(path = "/im/main")
public class ImMainActivity extends AbsActivity<ActImMainBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.act_im_main;
    }

    @Override
    protected void main() {

        MessageUtils.getInstance().login(SPUtils.getInstance().getStringValue(IM_LOGIN), data -> {
            L.e(TAG, SPUtils.getInstance().getStringValue(XIAOMI_PUSH_REGID)+"-------------");
            MessageUtils.getInstance().setOfflinePush(14774, SPUtils.getInstance().getStringValue(XIAOMI_PUSH_REGID), null);
            initViewPager();
        });
    }

    @Override
    protected void initListener() {

    }

    private void initViewPager() {
        List<Fragment> mViewList = new ArrayList<>();
        mBinding.viewPager.setOffscreenPageLimit(3);
        mViewList.add(ImConversationFragment.getInstance());
        mViewList.add(ImFriendsFragment.getInstance());
        mViewList.add(ImMyFragment.getInstance());
        mBinding.viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), mViewList));
        mBinding.tabGroup.setViewPager(mBinding.viewPager);
    }

//    private boolean shouldInit() {
//        ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
//        List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
//        String mainProcessName = getApplicationInfo().processName;
//        int myPid = Process.myPid();
//        for (ActivityManager.RunningAppProcessInfo info : processInfos) {
//            if (info.pid == myPid && mainProcessName.equals(info.processName)) {
//                return true;
//            }
//        }
//        return false;
//    }

}
